# 使用 realpath 获取脚本的绝对路径
SCRIPT_PATH=$(realpath "$0")
echo SCRIPT_PATH=$SCRIPT_PATH

# 获取脚本所在目录
SCRIPT_DIR=$( cd -- "$( dirname -- "${SCRIPT_PATH}" )" && pwd )
echo SCRIPT_DIR=$SCRIPT_DIR

BUILD_DIR_NAME=$1
echo BUILD_DIR_NAME=$BUILD_DIR_NAME

# 获取系统名称
os_name=$(uname -s)

# 判断是否为 Darwin（macOS）
if [ "$os_name" = "Darwin" ]; then
    echo "This is a Mac computer."
    export BUILD_SYS_ROOT="-isysroot $(xcrun --show-sdk-path)"
else
    export BUILD_SYS_ROOT=""
fi

# 获取上一级目录
PARENT_DIR=$(dirname "$SCRIPT_DIR")
echo PARENT_DIR=$PARENT_DIR

BUILD_ROOT_DIR=$PARENT_DIR/$BUILD_DIR_NAME/$MY_LLVM_BUILD_GEN/Debug

if [ ! -d "${BUILD_ROOT_DIR}" ]; then
    BUILD_ROOT_DIR=$PARENT_DIR/$BUILD_DIR_NAME/Clion/Debug
fi

BUILD_BIN_DIR=$BUILD_ROOT_DIR/bin

if [ "$os_name" = "Darwin" ]; then
    CMAKE_BIN=/Applications/CMakec-3.31.7-universal.app/Contents/bin/cmake
else
    CMAKE_BIN=cmake
fi

echo BUILD_BIN_DIR=${BUILD_BIN_DIR}
echo CMAKE_BIN=${CMAKE_BIN}

export BUILD_ROOT_DIR
export BUILD_BIN_DIR
export MY_LLVM_BUILD_GEN=Ninja
export PATH=$BUILD_BIN_DIR:$SCRIPT_DIR/example:$PATH
export CMAKE_BIN



echo BUILD_SYS_ROOT=$BUILD_SYS_ROOT